package homewoek12月12号.homework2.h1;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.List;

public class demo2 {
    public static void main(String[] args) throws Exception {
        /*SAXReader reader = new SAXReader();
        Document read = reader.read("D:\\ldea dashuju\\day.12.11\\src\\czxy\\homework\\h1\\city.xml");
        Element root = read.getRootElement();
        List<Element> city = root.elements("city");
        for (Element citys:city){
            List<Element> list = citys.elements();
            System.out.println(list.toString());
            System.out.println("citys:"+citys.attributeValue("id")+citys.attributeValue("sex"));
            *//*Element cityname = citys.element("cityname");
            System.out.println(cityname.attributeValue("id"));*//*
            System.out.println("cityname:"+citys.elementText("cityname"));
            System.out.println("cityarea:"+citys.elementText("cityarea"));
            System.out.println("population:"+citys.elementText("population"));
        }*/
        SAXReader saxReader = new SAXReader();
        Document read1 = saxReader.read("D:\\ldea dashuju\\day.12.11\\src\\czxy\\homework\\h1\\city.xml");
        Element root = read1.getRootElement();
        List<Element> elist = root.elements();
        for (Element element : elist) {
            System.out.println(element.getName()+"  id="+element.attributeValue("id"));
            System.out.println(element.elementText("cityname"));
            System.out.println(element.elementText("cityarea"));
            System.out.println(element.elementText("population"));
        }
        /*SAXReader reader = new SAXReader();
        Document read = reader.read("D:\\ldea dashuju\\day.12.11\\src\\czxy\\homework\\h1\\city.xml");
        Element root = read.getRootElement();
        List<Element> clist = root.elements("city");
        for (Element element : clist) {
            System.out.println(element.getName()+"  "+element.attributeValue("id"));
            System.out.println(element.elementText("cityname"));
            System.out.println(element.elementText("cityarea"));
            System.out.println(element.elementText("population"));
        }*/
    }
}
